<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
    <script
      src="../../day34/jquery.min.js"
      type="text/javascript"
      charset="utf-8"
    ></script>
  </head>
  <body>
    <input type="file" class="myimg" />
    <button class="btn1">发送get请求</button>
    <button class="btn2">发送post请求</button>
    <button class="btn3">发送文件</button>
    <script type="text/javascript">
      $(".btn1").click(function () {
        // $.ajax({
        // 	url:"get.php",
        // 	data:{
        // 		p:1
        // 	},
        // 	dataType:"json",
        // 	success(res){
        // 		console.log(res);
        // 	}
        // })
        $.get("get.php", { p: 1 }, function (res) {
          console.log(res);
        });
      });
      $(".btn2").click(function () {
        // $.post("post.php",{p:1},function(res){
        // 		console.log(res);
        // })
        $.ajax({
          url: "post.php",
          method: "post",
          data: {
            p: 2,
          },
          dataType: "json",
        }).then((res) => {
          console.log(res);
        });
      });

      $(".btn3").click(function () {
        let imgEle = $(".myimg")[0].files[0];
        // console.log(imgEle)
        let form = new FormData();
        form.append("myimg", imgEle);
        $.ajax({
          url: "file.php",
          method: "post",
          contentType: false,
          processData: false,
          data: form,
          success(res) {
            console.log(res);
          },
        });
      });
    </script>
  </body>
</html>
